package com.xxx.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonSwitchUtil{

    public static void toJsonString(HttpServletRequest req, HttpServletResponse resp,Object O) throws ServletException, IOException {
        String jsonString = JSON.toJSONString(O);
        resp.setContentType("applicaton/json,charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        PrintWriter writer = resp.getWriter();
        writer.write(jsonString);
    }

}
